package com.qf.controller;

import com.wf.captcha.SpecCaptcha;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@RestController
@RequestMapping("/captcha")
@CrossOrigin
public class CaptchaContorller {

    @GetMapping
    public void getCptcha(HttpSession session, HttpServletResponse resp) throws IOException {
        SpecCaptcha specCaptcha = new SpecCaptcha(180,34,6);
        String code = specCaptcha.text();
        System.out.println(code);
        session.setAttribute("code",code);
        System.out.println(session.getAttribute("code"));
        specCaptcha.out(resp.getOutputStream());
    }
}
